package com.tianpengtech.admin.permission;


import com.jfinal.plugin.activerecord.Db;
import com.tianpengtech.common.model.permission.Permission;
import com.tianpengtech.common.model.permission.PermissionDispather;

import java.util.List;

public class PermissionDao {
    public static PermissionDao ME = new PermissionDao();

    /*
        根据role查找对应的操作权限
     */
    public List<PermissionDispather> queryPermissionByRole(String roleName){
        String sql="select * from "+ PermissionDispather.dao.tableName()+" where "+PermissionDispather.ROLE+"=? limit 1";
        return PermissionDispather.dao.find(sql, roleName);
    }

    /*
       根据role查找对应的唯一的操作权限
    */
    public PermissionDispather queryUniquePermissionByRole(String roleName){
        String sql="select * from "+ PermissionDispather.dao.tableName()+" where "+PermissionDispather.ROLE+"=? limit 1";
        return PermissionDispather.dao.findFirst(sql, roleName);
    }

    /*
        根据模块ID查询对应模块下的权限操作
     */
    public List<Permission> queryPermissionByRefId(long id){
        String sql="select * from "+ Permission.dao.tableName()+" where "+Permission.REF_ID+"=? ";
        return Permission.dao.find(sql, id);
    }
}
